home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / wxmodem.zip / WXMOXFER.INC < prev   
Text File  |  1986-11-06  |  40KB  |  1,006 lines

  1. {$U-,C-,R-,K-}
  2.   {   - modified to add CRC xmodem, wxmodem 7/86 - 10/86
  3. Peter Boswell
  4. ADI
  5. Suite 650
  6. 350 N. Clark St.
  7. Chicago, Il 60610
  8. People/Link: Topper
  9. Compuserve : 72247,3671
  10.   }
  11. const
  12.      SOH = 1;                          {Start Of Header}
  13.      EOT = 4;                          {End Of Transmission}
  14.      ACK = 6;                          {ACKnowledge}
  15.      DLE = $10;                        {Data Link Escape}
  16.      XON = $11;                        {X-On}
  17.      XOFF = $13;                       {X-Off}
  18.      NAK = $15;                        {Negative AcKnowledge}
  19.      SYN = $16;                        {Synchronize}
  20.      CAN = $18;                        {CANcel}
  21.      CHARC = $43;                      {C = CRC Xmodem}
  22.      CHARW = $57;                      {W = WXmodem}
  23.      MAXERRS = 10;                     {Maximum allowed errors}
  24.      L = 0;
  25.      H = 1;
  26.      Buflen  = 128;                    {Disk I/O buffer length}
  27.      Bufnum = 64;                      {Disk I/O buffer count}
  28.      Maxwindow = 4;                    {Wxmodem window size}
  29.                                        {CRC byte translation table}
  30.      Crctab: array[0..255] of Integer =
  31.      (0, 4129, 8258, 12387, 16516, 20645, 24774, 28903,
  32.       -32504,-28375,-24246,-20117,-15988,-11859,-7730,-3601,
  33.       4657, 528, 12915, 8786, 21173, 17044, 29431, 25302,
  34.       -27847,-31976,-19589,-23718,-11331,-15460,-3073,-7202,
  35.       9314, 13379, 1056, 5121, 25830, 29895, 17572, 21637,
  36.       -23190,-19125,-31448,-27383,-6674,-2609,-14932,-10867,
  37.       13907, 9842, 5649, 1584, 30423, 26358, 22165, 18100,
  38.       -18597,-22662,-26855,-30920,-2081,-6146,-10339,-14404,
  39.       18628, 22757, 26758, 30887, 2112, 6241, 10242, 14371,
  40.       -13876,-9747,-5746,-1617,-30392,-26263,-22262,-18133,
  41.       23285, 19156, 31415, 27286, 6769, 2640, 14899, 10770,
  42.       -9219,-13348,-1089,-5218,-25735,-29864,-17605,-21734,
  43.       27814, 31879, 19684, 23749, 11298, 15363, 3168, 7233,
  44.       -4690,-625,-12820,-8755,-21206,-17141,-29336,-25271,
  45.       32407, 28342, 24277, 20212, 15891, 11826, 7761, 3696,
  46.       -97,-4162,-8227,-12292,-16613,-20678,-24743,-28808,
  47.       -28280,-32343,-20022,-24085,-12020,-16083,-3762,-7825,
  48.       4224, 161, 12482, 8419, 20484, 16421, 28742, 24679,
  49.       -31815,-27752,-23557,-19494,-15555,-11492,-7297,-3234,
  50.       689, 4752, 8947, 13010, 16949, 21012, 25207, 29270,
  51.       -18966,-23093,-27224,-31351,-2706,-6833,-10964,-15091,
  52.       13538, 9411, 5280, 1153, 29798, 25671, 21540, 17413,
  53.       -22565,-18438,-30823,-26696,-6305,-2178,-14563,-10436,
  54.       9939, 14066, 1681, 5808, 26199, 30326, 17941, 22068,
  55.       -9908,-13971,-1778,-5841,-26168,-30231,-18038,-22101,
  56.       22596, 18533, 30726, 26663, 6336, 2273, 14466, 10403,
  57.       -13443,-9380,-5313,-1250,-29703,-25640,-21573,-17510,
  58.       19061, 23124, 27191, 31254, 2801, 6864, 10931, 14994,
  59.       -722,-4849,-8852,-12979,-16982,-21109,-25112,-29239,
  60.       31782, 27655, 23652, 19525, 15522, 11395, 7392, 3265,
  61.       -4321,-194,-12451,-8324,-20581,-16454,-28711,-24584,
  62.       28183, 32310, 20053, 24180, 11923, 16050, 3793, 7920);
  63.  
  64. {*** variables used as globals in this source segment
  65.      (actually global to whole  source) ***}
  66. var
  67.    checksum     : integer;
  68.    tblks        : integer;
  69.    fname        : bigstring;
  70.    response     : string[1];
  71.    crcval,db,sb : integer;
  72.    packetln     : integer;            {128 + Checksum or 128 + CRC}
  73.    p            : parity_set;
  74.    dbuffer      : array[1..Bufnum,1..Buflen] of byte;
  75.    dcount       : integer;
  76.    Wxmode       : boolean;
  77.    Crcmode      : boolean;
  78.    Openflag     : boolean;
  79.    Windowfl     : boolean;
  80.  
  81.  
  82. procedure updcrc(a : byte);
  83. begin
  84.   {
  85.      crcval := Crctab[hi(crcval) xor a] xor (lo(crcval) shl 8);
  86.   }
  87.      inline(
  88.  
  89.         $A1/crcval/       {mov ax,crcval     AX <- crcval}
  90.         $89/$C2/          {mov dx,ax         DX <- crcval}
  91.         $88/$E0/          {mov al,ah         (AX) crcval >> 8}
  92.         $B4/$00/          {mov ah,0 }
  93.         $36/              {ss:}
  94.         $8B/$8E/a/        {mov cx,[bp+a]     CX <- a}
  95.         $31/$C8/          {xor ax,cx         AX <- (crcval >> 8) xor a}
  96.         $D1/$E0/          {shl ax,1          AX <- AX * 2  (word index)}
  97.         $BB/crctab/       {mov bx,offset crctab   BX <- addr(crctab)}
  98.         $01/$C3/          {add bx,ax         BX <- addr(crctab)+((crcval>>8)xor a)*2 }
  99.         $2E/              {cs:}
  100.         $8B/07/           {mov ax,[bx]       AX <- contents of crctab}
  101.         $88/$D6/          {mov dh,dl         (DX) crcval << 8}
  102.         $B2/$00/          {mov dl,00}
  103.         $31/$D0/          {xor ax,dx         AX <- contents of crctab xor crcval << 8}
  104.         $A3/crcval        {mov crcval,ax     crcval <- AX}
  105.  
  106.           );
  107. end;
  108. { Xmodem transmit window routine
  109.   Peter Boswell, July 1986       }
  110.  
  111. procedure txwindow(opt : integer; in_string : bigstring);
  112.  
  113. begin
  114.    if not displayfl then
  115.       exit;
  116.    case opt of
  117.        1  :     begin                           {initialize}
  118.                    OpenTemp(36,3,78,18,2);
  119.                    Windowfl := true;
  120.                    Clrscr;
  121.                    GotoXY(10,1);
  122.                    write('File - ',in_string);
  123.                    GotoXY(10,2);
  124.                    write('Mode -');
  125.                    GotoXY(4,3);
  126.                    write('Total time -');
  127.                    GotoXY(2,4);
  128.                    write('Total Blocks -');
  129.                    GotoXY(10,5);
  130.                    write('Sent -');
  131.                    GotoXY(9,6);
  132.                    write('ACK''d -');
  133.                    GotoXY(6,7);
  134.                    write('Last NAK -');
  135.                    GotoXY(9,8);
  136.                    write('X-Off - No');
  137.                    GotoXY(8,9);
  138.                    write('Window - 0');
  139.                    GotoXY(4,11);
  140.                    write('Last Error -');
  141.                    GotoXY(8,10);
  142.                    write('Errors -');
  143.                 end;
  144.        2..11  : begin
  145.                    GotoXY(17,opt);
  146.                    ClrEol;
  147.                    write(in_string);
  148.                 end;
  149.        12     : begin
  150.                    GotoXY(3,12);
  151.                    ClrEol;
  152.                    write(in_string);
  153.                 end;
  154.        99     : begin
  155.                    if windowfl then
  156.                       CloseTemp;
  157.                 end;
  158.  
  159.    end;                                         {case}
  160. end;
  161. { Xmodem receive window routine
  162.   Peter Boswell, October 1986       }
  163.  
  164. procedure trwindow(opt : integer; in_string : bigstring);
  165.  
  166. begin
  167.    if not displayfl then
  168.        exit;
  169.    case opt of
  170.        1  :     begin                           {initialize}
  171.                    windowfl := true;
  172.                    OpenTemp(36,3,78,13,2);
  173.                    Clrscr;
  174.                    GotoXY(10,1);
  175.                    write('File - ',in_string);
  176.                    GotoXY(10,2);
  177.                    write('Mode -');
  178.                    GotoXY(6,3);
  179.                    write('Received -');
  180.                    GotoXY(6,4);
  181.                    write('Last NAK -');
  182.                    GotoXY(4,5);
  183.                    write('Last Error -');
  184.                    GotoXY(8,6);
  185.                    write('Errors -');
  186.                 end;
  187.        2..6   : begin
  188.                    GotoXY(17,opt);
  189.                    ClrEol;
  190.                    write(in_string);
  191.                 end;
  192.        8      : begin
  193.                    GotoXY(3,8);
  194.                    ClrEol;
  195.                    write(in_string);
  196.                 end;
  197.        99     : begin
  198.                    if windowfl then
  199.                       CloseTemp;
  200.                 end;
  201.    end;                                         {case}
  202. end;
  203.  
  204. {
  205.   This routine deletes all DLE characters and XOR's the following character
  206.   with 64.  If a SYN character is found then -2 is returned.
  207.     }
  208. function dlecgetc(Tlimit : integer) : integer;
  209. var
  210. savecgetc : integer;
  211. begin
  212.      if wxmode then
  213.      begin
  214.           savecgetc := cgetc(Tlimit);
  215.           if savecgetc = SYN then
  216.              savecgetc := -2
  217.           else
  218.